package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordMusic;
import com.letian.record.service.IRecordMusicService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 记录歌曲Controller
 * 
 * @author bmz
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/record/music")
public class RecordMusicController extends BaseController
{
    @Autowired
    private IRecordMusicService recordMusicService;

    /**
     * 查询记录歌曲列表
     */
    @PreAuthorize("@ss.hasPermi('record:music:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordMusic recordMusic)
    {
        startPage();
        List<RecordMusic> list = recordMusicService.selectRecordMusicList(recordMusic);
        return getDataTable(list);
    }

    /**
     * 导出记录歌曲列表
     */
    @PreAuthorize("@ss.hasPermi('record:music:export')")
    @Log(title = "记录歌曲", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordMusic recordMusic)
    {
        List<RecordMusic> list = recordMusicService.selectRecordMusicList(recordMusic);
        ExcelUtil<RecordMusic> util = new ExcelUtil<RecordMusic>(RecordMusic.class);
        util.exportExcel(response, list, "记录歌曲数据");
    }

    /**
     * 获取记录歌曲详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:music:query')")
    @GetMapping(value = "/{musicId}")
    public AjaxResult getInfo(@PathVariable("musicId") Long musicId)
    {
        return success(recordMusicService.selectRecordMusicByMusicId(musicId));
    }

    /**
     * 新增记录歌曲
     */
    @PreAuthorize("@ss.hasPermi('record:music:add')")
    @Log(title = "记录歌曲", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordMusic recordMusic)
    {
        recordMusic.setCreateBy(getUsername());
        return toAjax(recordMusicService.insertRecordMusic(recordMusic));
    }

    /**
     * 修改记录歌曲
     */
    @PreAuthorize("@ss.hasPermi('record:music:edit')")
    @Log(title = "记录歌曲", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordMusic recordMusic)
    {
        recordMusic.setUpdateBy(getUsername());
        Long count = recordMusic.getUpdateCount() == null ? 1 : recordMusic.getUpdateCount() + 1;
        recordMusic.setUpdateCount(count);
        return toAjax(recordMusicService.updateRecordMusic(recordMusic));
    }

    /**
     * 删除记录歌曲
     */
    @PreAuthorize("@ss.hasPermi('record:music:remove')")
    @Log(title = "记录歌曲", businessType = BusinessType.DELETE)
	@DeleteMapping("/{musicIds}")
    public AjaxResult remove(@PathVariable Long[] musicIds)
    {
        return toAjax(recordMusicService.deleteRecordMusicByMusicIds(musicIds));
    }
}
